<template>
  <aside class="sidebar">
    <div class="user-info">
      <img :src="userAvatar" alt="用户头像" id="user-avatar">
      <span id="user-status">在线</span>
      <button @click="$emit('logout')">注销</button>
    </div>
    <input type="text" v-model="searchQuery" placeholder="搜索菜单...">
    <div class="menu">
      <div v-for="item in filteredMenus" :key="item.name" @click="navigateToMenu(item.route)">
        {{ item.name }}
      </div>
    </div>
  </aside>
</template>

<script>
export default {
  props: ['menus'],
  data() {
    return {
      searchQuery: '',
      userAvatar: 'default-avatar.png'
    };
  },
  computed: {
    filteredMenus() {
      if (!this.searchQuery) {
        return this.menus;
      }
      const query = this.searchQuery.toLowerCase();
      return this.menus.filter(item => item.name.toLowerCase().includes(query));
    }
  },
  methods: {
    navigateToMenu(route) {
      this.$router.push({ path: route });
    }
  }
};
</script>

<style scoped>
.sidebar {
  width: 250px;
  background-color: #f4f4f4;
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

#user-avatar {
  border-radius: 50%;
  width: 80px;
  height: 80px;
}

.menu {
  flex-grow: 1;
}
</style>